﻿@model Gman.WebApp.Models.ServicioModel
           
<style>
    .ui-widget
    {
        font-size: 0.8em;
    }
    .ui-dialog .ui-dialog-content
    {
        padding:0px;
    }
</style>

<div  runat="server" id="PopupGUID" />

@{
    string PopupGUID = Guid.NewGuid().ToString();
}

<div id="BienesPopup_@(PopupGUID)" >

<div>
 <table width="100%" class="GridLista">
    <tr  class="HeaderStyle">
     <th>
         Tipo
        </th>
        <th>
           Codigo
        </th>
        <th>
           Descripcion
        </th>
        <th>
            Ir
        </th>
    </tr>   
    
 
@if (Model.Bienes != null)
    {
        foreach (var item in Model.Bienes)
        { 
     <tr class="ItemStyle">           
            <td style="width:100px"> @(Html.Encode(item.TipoBien))</td>
            <td style="width:400px"> @(Html.Encode(item.CodBien))</td>
            <td style="width:100px"> @(Html.Encode(item.DescBien))</td>
           
   
<td style="width:100px">
      
        <a class="ActionLink" id="Add" href="#" onclick="AddBien('@( item.IDBien )', true)">Agregar</a>          
           </td>  
        </tr>
}
    }
    

</table>
</div>

<div>
 <table width="100%" class="GridLista">
    <tr  class="HeaderStyle">
    <th>
         Tipo
        </th>
        <th>
           Codigo
        </th>
        <th>
           Descripcion
        </th>
           <th>
            Ir
        </th>
    </tr>   
    
 
@if (Model.Servicio.LstBienes != null)
    {
        foreach (var item in Model.Servicio.LstBienes)
        { 
     <tr class="ItemStyle">           
            <td style="width:100px"> @(Html.Encode(item.TipoBien))</td>
            <td style="width:400px"> @(Html.Encode(item.CodBien))</td>
            <td style="width:100px"> @(Html.Encode(item.DescBien))</td>
           
   
<td style="width:100px">
      
        <a class="ActionLink" href="#" onclick="DelBien('@( item.IDBien )', true)">Quitar</a>          
           </td>  
        </tr>
}
    }
    

</table>
</div>

</div>


<script type="text/javascript">

    var personalGuid = "@( Model.ID.ToString())";
    var action = "@( Model.Action.ToString())";

    $(document).ready(function () {

        $("[id^='BienesPopup_']").change(function () { UpdateFieldPersonal(this); });
        $(".date").change(function () { parseAndSetDt(this); });

        SetupDialog();
    });

    function SetupDialog() {
        var popupTitle = "Bienes asociados al Servicio";

        $("#BienesPopup_@( PopupGUID )").dialog({
            modal: true,
            resizable: false,
            title: popupTitle,
            width: 800,
            height: 'auto',
            autoOpen: true,
            buttons:
            {
                //"Grabar": function() { SavePersonal(); },
                "Aceptar": function () { $(this).dialog("close"); }

            },
            close: function (event, ui) {
                $(this).dialog("destroy");
                $("#BienesPopUpDiv").empty();
            }
        });

        $("#BienesPopup_@( PopupGUID )").dialog("open");
    }

    function SavePersonal() {

        AddOrEditPersonal(action);
        $("#BienesPopup_@( PopupGUID )").dialog("close");
    }


    function AddBien(idBien) {

        var data = { id: guid,
            idBien: idBien
        };
        $.ajax({
            type: "POST",
            data: data,
            url: window.GetControllerUrl("AgregarBien", "Servicio"),
            success: function (result) {
                $("#BienesPopup_@( PopupGUID )").dialog("close");
                $("#BienesPopUpDiv").html(result);

                DeshabiCampos();
            },
            error: function (result) {
                alert("Data not found");
            }
        });
    }

    function DelBien(idBien) {

        var data = { id: guid,
            idBien: idBien
        };
        $.ajax({
            type: "POST",
            data: data,
            url: window.GetControllerUrl("QuitarBien", "Servicio"),
            success: function (result) {
                $("#BienesPopup_@( PopupGUID )").dialog("close");
                $("#BienesPopUpDiv").html(result);
                DeshabiCampos();
            },
            error: function (result) {
                alert("Data not found");
            }
        });
    }


</script>